{extend name="public:base" /}

{block name="body"}
<div class="main" style="padding:15px;">
    <div class="content">
        <span style="margin-left: 0;display: inline-block">购物车列表</span>
        <span class="userinfo" id="total">总价格:0</span>
        <div></div>
    </div>

    <table class="layui-table">
        <thead>
        <tr>
            <th style="text-align: center;font-weight: bold">商品ID</th>
            <th style="text-align: center;font-weight: bold">商品标题</th>
            <th style="text-align: center;font-weight: bold">原价</th>
            <th style="text-align: center;font-weight: bold">折扣</th>
            <th style="text-align: center;font-weight: bold">现价</th>
            <th style="text-align: center;font-weight: bold">数量</th>
            <th style="text-align: center;font-weight: bold">总计</th>
            <th style="text-align: center;font-weight: bold">状态</th>
            <th style="text-align: center;font-weight: bold">时间</th>
            <th colspan="2" style="text-align: center;font-weight: bold">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="right" id='right'}
        <tr>
            <td style="text-align: center">{$right.goods_id}</td>
            <td style="text-align: center">{$right.title}</td>
            <td style="text-align: center">{$right.price}</td>
            <td style="text-align: center">{$right.discount}</td>
            <td style="text-align: center">
                {if $right.discount <> 0}
                {$right.discount*0.1*$right.price}
                {else/}{$right.price}
                {/if}
            </td>
            <td style="text-align: center">{$right.quantity}</td>
            <td style="text-align: center">{$right.total_money}</td>

            <input type="hidden" id="to" value="{$count = $count + $right.total_money}">

            <td style="text-align: center">
                {if $right.status == 1}
                    <span style="color: red">等待发货</span>
                {/if}
                {if $right.status == 2}
                    <span style="color: darkmagenta">等待收货</span>
                {/if}
                {if $right.status == 0}
                    <span style="color: green">交易成功</span>
                {/if}
            </td>

            <td style="text-align: center">{$right.create_time|date='Y-m-d H:i'}</td>

            <td style="text-align: center" >
            {if $right.status == 1 }
                <button class="layui-btn layui-btn-xs"  onclick="cancel({$right.goods_id},{$right.quantity},{$right.id})">申请退款</button>
            {elseif $right.status == 0}
                <button class="layui-btn layui-btn-xs"  onclick="cancel({$right.goods_id},{$right.quantity},{$right.id})">申请退货</button>
            {else}
                <button class="layui-btn-default layui-btn-xs"  onclick="javascript:;">没有操作</button>
            {/if}
            <td style="text-align: center" >
                <button class="layui-btn-danger layui-btn-xs"  onclick="delOrder({$right.id})">删除订单</button>
            </td>
            </td>

        </tr>

        {/volist}
        </tbody>
    </table>
    <input type="hidden" id="to1" value="{$count}">

    <div style="align-self: center; margin: 0 auto;">
        <button class="layui-btn layui-btn-ms center-block" id="cart1" onclick="orderRec()">订单回收站</button>
    </div>

    <div style="text-align: center">{$rightList|raw}</div>

</div>

<script>
    // window.onload=function () {
    //     let total_m = document.getElementById('to1');
    //     $('#total').text(total_m.value);
    // }
    document.onreadystatechange = function () {
        if(document.readyState === "complete"){ //当页面加载状态为完全结束时进入
            var total_m = document.getElementById('to1');
            $('#total').text('花费的金钱数：'+total_m.value);
        }
    }
</script>

<script>
    function cancel(goods_id,quantity,id){
        layer.confirm('确定取消订单号为 '+goods_id+' 的订单吗', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('/index.php/user/cancel',{'goods_id':goods_id,'quantity':quantity,'id':id},function(res){
                if(res.status == 0){
                    layer.alert(res.message,{icon:2});
                }else{
                    layer.msg('取消成功，你这逗比，没钱还要买');
                    setTimeout(function () {
                        window.location.reload();
                    },2000);
                }
            },'json');
        });
    }
</script>

<script>
    function delOrder(id){
        layer.confirm('确定删除订单号为 '+id+' 的订单吗？温馨提示：删除订单只是将订单从列表删除，不会造成其他影响', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('/index.php/user/delOrder',{'id':id},function(res){
                if(res.status == 0){
                    layer.alert(res.message,{icon:2});
                }else{
                    layer.msg('取消成功，你这逗比，没钱还要买');
                    setTimeout(function () {
                        window.location.reload();
                    },2000);
                }
            },'json');
        });
    }
</script>

<script type="text/javascript">
    function orderRec(){
        layer.open({
            type: 2,
            title: '订单恢复',
            shade: 0.3,
            area: ['1050px', '600px'],
            content: '/index.php/user/orderrec'
        });
    }
</script>


{/block}

